package cn.com.thingo.hyintelligent.ui.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.th.opensdk.openapi.CurtainInfo;
import com.th.opensdk.openapi.SceneInfo;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.com.thingo.hyintelligent.R;

public class WindowListAdapter extends RecyclerView.Adapter<WindowListAdapter.ViewHolder> {
    private List<SceneInfo> list;
    private Context context;
    private CallBack callBack;


    public WindowListAdapter(List<SceneInfo> sceneInfoList, Context mContext) {
        this.list = sceneInfoList;
        this.context = mContext;
    }

    public void setCallBack(CallBack callBack) {
        this.callBack = callBack;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ViewHolder(LayoutInflater.from(context).inflate(R.layout.item_window_list, parent, false));
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, @SuppressLint("RecyclerView") final int position) {
        final SceneInfo sceneInfo = list.get(position);
        holder.tvName.setText(sceneInfo.getSceneName().split("-")[1]);
        if (callBack != null) {
            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    callBack.callBack(sceneInfo);
                }
            });
        }


    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.item_window_name)
        TextView tvName;

        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    public interface CallBack {
        void callBack(SceneInfo sceneInfo);
    }
}
